package enemy.actions;

import utility.Util;
import enemy.Enemy;


public class GoToWaypoint implements Action {
	private float x;
	private float y;
	
	public GoToWaypoint(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public float getX() {
		return x;
	}
	
	public float getY() {
		return y;
	}

	@Override
	public boolean execute(Enemy enemy) {
		
		float target = enemy.getTargetRotation(x, y); //angle we want to be at (0-359)

		float current = enemy.getRotation();
		
		target = (target+360f) % 360f;
		current = (current+360f) % 360f;
		
		if(target==current) { // we are facing it
			return enemy.move(x, y);
		} else { //not facing it
			//turn to face it
			if(enemy.getDirection(target)) {
				return enemy.turnRight(target, 1.0f);
			} else {
				return enemy.turnLeft(target, 1.0f);
			}
		}
//		
//		enemy.setRotation(Util.scale(enemy.getRotation())); //scale the rotation
//		
//		return false;
	}
}